import java.awt.event.*;
import java.io.File;
import java.sql.SQLException;

import javax.swing.*;

/*
import nz.ac.massey.doi_information_extractor.data.*;
import nz.ac.massey.doi_information_extractor.database.DBcontroller;
import nz.ac.massey.doi_information_extractor.output.PDFOutputInterface;
import nz.ac.massey.doi_information_extractor.parser.*;
import nz.ac.massey.doi_information_extractor.database.DBimpl;
*/

@SuppressWarnings("serial")
public class DisableEnableGUI extends JFrame {

	private JButton searchButton, outputButton, saveButton;
	private JLabel enterDOILabel, nameLabel, idLabel, unitLabel, mailCodeLabel,
			typeOfWorkLabel, qaLabel, confLabel, contribTypeLabel,
			specificContribLabel, authorsLabel, issnLabel, articleTitleLabel,
			volNumLabel, pubTitleLabel, pgNumLabel, urlLabel, yearLabel,
			publisherLabel, receiptLabel, descriptionLabel;
	private JTextField enterDOIBox, nameBox, idBox, unitBox, mailCodeBox,
			authorsBox, issnBox, articleTitleBox, volNumBox, pubTitleBox,
			pageNumBox, urlBox, yearBox, publisherBox;
	private JRadioButton research, pro_Comm, qaYes, qaNo, confYes, confNo;
	private JTextArea descriptionArea;
	private JScrollPane descriptionScroll;
	private JList contribTypeList, specificContribList;

	/*
	private ParserEngine currentParser;
	private Publication currentPublication;
	private DBcontroller currentDB;
	private PDFOutputInterface currentPDFOutput;
	*/

	public DisableEnableGUI() {

	//	currentParser = new ParserEngine();
		JPanel form = new JPanel();
		form.setLayout(null);

		// label, text field, and button for entering a DOI and getting
		// information
		enterDOILabel = new JLabel("Enter DOI");
		enterDOILabel.setBounds(20, 20, 80, 25);
		form.add(enterDOILabel);
		
		enterDOIBox = new JTextField();
		enterDOIBox.setBounds(90, 20, 450, 25);
		form.add(enterDOIBox);

		searchButton = new JButton("Search");
		searchButton.setBounds(550, 20, 100, 25);
		searchButton.addActionListener(new searchButtonListener());
		form.add(searchButton);// end search for DOI

		saveButton = new JButton("Save");
		saveButton.setBounds(440, 50, 100, 25);
		saveButton.addActionListener(new saveButtonListener());
		form.add(saveButton);// end search for DOI

		outputButton = new JButton("Output");
		outputButton.setBounds(550, 50, 100, 25);
		outputButton.addActionListener(new outputButtonListener());
		form.add(outputButton);// end search for DOI

		// label and text box for the name of the submitter
		nameLabel = new JLabel("Name:");
		nameLabel.setBounds(20, 80, 80, 25);
		form.add(nameLabel);

		nameBox = new JTextField();
		nameBox.setBounds(90, 80, 150, 25);
		nameBox.setEnabled(false);
		form.add(nameBox);// end name

		// label and text box for the id of the submitter
		idLabel = new JLabel("ID:");
		idLabel.setBounds(20, 110, 80, 25);
		form.add(idLabel);

		idBox = new JTextField();
		idBox.setBounds(90, 110, 150, 25);
		idBox.setEnabled(false);
		form.add(idBox);// end id

		// label and text box for the unit the submitter is in (e.g. SEAT)
		unitLabel = new JLabel("Unit:");
		unitLabel.setBounds(20, 140, 80, 25);
		form.add(unitLabel);

		unitBox = new JTextField();
		unitBox.setBounds(90, 140, 150, 25);
		unitBox.setEnabled(false);
		form.add(unitBox);// end unit

		// label and text box for the mail code of the submitter
		mailCodeLabel = new JLabel("Mail Code:");
		mailCodeLabel.setBounds(20, 170, 80, 25);
		form.add(mailCodeLabel);

		mailCodeBox = new JTextField();
		mailCodeBox.setBounds(90, 170, 150, 25);
		mailCodeBox.setEnabled(false);
		form.add(mailCodeBox);// end mail code

		// set of radio buttons and label for the type of research
		typeOfWorkLabel = new JLabel("Type of Research:");
		typeOfWorkLabel.setBounds(280, 80, 120, 25);
		form.add(typeOfWorkLabel);

		research = new JRadioButton("Research");
		research.setBounds(390, 80, 80, 25);
		research.setEnabled(false);
		form.add(research);

		pro_Comm = new JRadioButton("Professional/Community");
		pro_Comm.setBounds(480, 80, 180, 25);
		pro_Comm.setEnabled(false);
		form.add(pro_Comm);

		ButtonGroup researchGroup = new ButtonGroup(); // groups research
		researchGroup.add(research);
		researchGroup.add(pro_Comm);// end type of research

		// set of radio buttons and label for whether the publication has had
		// quality assurance
		qaLabel = new JLabel("QA:");
		qaLabel.setBounds(280, 110, 120, 25);
		form.add(qaLabel);

		qaYes = new JRadioButton("Yes");
		qaYes.setBounds(390, 110, 80, 25);
		qaYes.setEnabled(false);
		form.add(qaYes);

		qaNo = new JRadioButton("No");
		qaNo.setBounds(480, 110, 180, 25);
		qaNo.setEnabled(false);
		form.add(qaNo);

		ButtonGroup qaGroup = new ButtonGroup(); // groups QA
		qaGroup.add(qaYes);
		qaGroup.add(qaNo);// end QA

		// Set of radio buttons for whether the document is confidential
		confLabel = new JLabel("Confidential:");
		confLabel.setBounds(280, 140, 120, 25);
		form.add(confLabel);

		confYes = new JRadioButton("Yes");
		confYes.setBounds(390, 140, 80, 25);
		confYes.setEnabled(false);
		form.add(confYes);

		confNo = new JRadioButton("No");
		confNo.setBounds(480, 140, 180, 25);
		confNo.setEnabled(false);
		form.add(confNo);

		ButtonGroup confGroup = new ButtonGroup(); // groups confidential
		confGroup.add(confYes);
		confGroup.add(confNo);// end confidential

		// List of contribution types, i.e. book, journal or conference.
		contribTypeLabel = new JLabel("Type of contribution:");
		contribTypeLabel.setBounds(20, 225, 150, 25);
		form.add(contribTypeLabel);

		String types[] = { "Journal", "Book excerpt", "Book chapter",
				"Conference" };
		contribTypeList = new JList(types);
		contribTypeList.setBounds(145, 225, 170, 90);
		contribTypeList.setSelectedIndex(0);
		contribTypeList.setEnabled(false);
		form.add(contribTypeList);// end contribution type

		// List of specific types for the contribution
		specificContribLabel = new JLabel("Specific contribution:");
		specificContribLabel.setBounds(330, 225, 150, 25);
		form.add(specificContribLabel);

		specificContribList = new JList();
		specificContribList.setBounds(460, 225, 170, 90);
		specificContribList.setEnabled(false);
		form.add(specificContribList);// end specific contribution type

		// label and text box for the authors of the publication
		authorsLabel = new JLabel("Authors:");
		authorsLabel.setBounds(20, 340, 80, 25);
		form.add(authorsLabel);

		authorsBox = new JTextField();
		authorsBox.setBounds(165, 340, 320, 25);
		authorsBox.setEnabled(false);
		form.add(authorsBox);// end authors

		// label and text box for the authors of the publication
		issnLabel = new JLabel("ISSN:");
		issnLabel.setBounds(500, 340, 80, 25);
		form.add(issnLabel);

		issnBox = new JTextField();
		issnBox.setBounds(600, 340, 50, 25);
		issnBox.setEnabled(false);
		form.add(issnBox);// end issn

		// label and text box for the article title
		articleTitleLabel = new JLabel("Article/Output Title:");
		articleTitleLabel.setBounds(20, 370, 150, 25);
		form.add(articleTitleLabel);

		articleTitleBox = new JTextField();
		articleTitleBox.setBounds(165, 370, 320, 25);
		articleTitleBox.setEnabled(false);
		form.add(articleTitleBox);// end article title

		// label and text box for the volume/number of the publication
		volNumLabel = new JLabel("Volume/Number:");
		volNumLabel.setBounds(500, 370, 130, 25);
		form.add(volNumLabel);

		volNumBox = new JTextField();
		volNumBox.setBounds(600, 370, 50, 25);
		volNumBox.setEnabled(false);
		form.add(volNumBox);// end volume/number

		// label and text box for the publication title
		pubTitleLabel = new JLabel("Journal/Publication Title:");
		pubTitleLabel.setBounds(20, 400, 150, 25);
		form.add(pubTitleLabel);

		pubTitleBox = new JTextField();
		pubTitleBox.setBounds(165, 400, 320, 25);
		pubTitleBox.setEnabled(false);
		form.add(pubTitleBox);// end publication title

		// label and text box for the
		pgNumLabel = new JLabel("Page Number:");
		pgNumLabel.setBounds(500, 400, 130, 25);
		form.add(pgNumLabel);

		pageNumBox = new JTextField();
		pageNumBox.setBounds(600, 400, 50, 25);
		pageNumBox.setEnabled(false);
		form.add(pageNumBox);// end

		// label and text box for the url
		urlLabel = new JLabel("URL:");
		urlLabel.setBounds(20, 430, 150, 25);
		form.add(urlLabel);

		urlBox = new JTextField();
		urlBox.setBounds(165, 430, 320, 25);
		urlBox.setEnabled(false);
		form.add(urlBox);// end url

		// label and text box for the
		yearLabel = new JLabel("Publication year:");
		yearLabel.setBounds(500, 430, 130, 25);
		form.add(yearLabel);

		yearBox = new JTextField();
		yearBox.setBounds(600, 430, 50, 25);
		yearBox.setEnabled(false);
		form.add(yearBox);// end

		// label and text box for the Publisher
		publisherLabel = new JLabel("Publisher:");
		publisherLabel.setBounds(20, 460, 150, 25);
		form.add(publisherLabel);

		publisherBox = new JTextField();
		publisherBox.setBounds(165, 460, 320, 25);
		publisherBox.setEnabled(false);
		form.add(publisherBox);// end Publisher

		// label and text area for the description
		descriptionLabel = new JLabel("Description:");
		descriptionLabel.setBounds(20, 500, 100, 25);
		form.add(descriptionLabel);

		descriptionArea = new JTextArea();
		descriptionArea.setBounds(110, 500, 540, 100);
		descriptionArea.setLineWrap(true);
		descriptionScroll = new JScrollPane(descriptionArea);
		descriptionArea.setEnabled(false);
		form.add(descriptionArea);// end description

		// basic set up of window
		pack();
		setSize(680, 650);
		setTitle("DOI Information Extractor");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
		add(form);
	}

	public static void main(String[] args) {
		new DisableEnableGUI();
	}

	public class searchButtonListener implements ActionListener {

		public void actionPerformed(ActionEvent arg0) {
	
		publisherBox.setEnabled(true);
		descriptionArea.setEnabled(true);
		contribTypeList.setEnabled(true);
		pageNumBox.setEnabled(true);
		pubTitleBox.setEnabled(true);
		qaYes.setEnabled(true);
		qaNo.setEnabled(true);
		confYes.setEnabled(true);
		confNo.setEnabled(true);
		research.setEnabled(true);
		pro_Comm.setEnabled(true);
		volNumBox.setEnabled(true);
		articleTitleBox.setEnabled(true);
		yearBox.setEnabled(true);
		urlBox.setEnabled(true);
		issnBox.setEnabled(true);
		idBox.setEnabled(true);
		authorsBox.setEnabled(true);
		unitBox.setEnabled(true);
		mailCodeBox.setEnabled(true);
		specificContribList.setEnabled(true);
		nameBox.setEnabled(true);
		
				
			/*		String doi = enterDOIBox.getText();
			Publication pub = new Publication();
			try {
				currentPublication = currentParser.getInformationFromDOI(doi,
						pub);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			pubTitleBox.setText(currentPublication.getPublicationTitle());
			pageNumBox.setText(currentPublication.getPageNumbers());
			articleTitleBox.setText(currentPublication.getArticleTitle());
			yearBox.setText(currentPublication.getDate());
			String authors = "";
			for (Author a : currentPublication.getAuthors()) {
				authors = authors + a.getactor_f_name() + " "
						+ a.getactor_l_name() + "; ";
			}
			authorsBox.setText(authors);
			volNumBox.setText(Integer.toString(currentPublication
					.getVolumeNumber()));
			issnBox.setText(currentPublication.getISSN());
			publisherBox.setText(currentPublication.getPublisher());
			descriptionArea.setText(currentPublication.getDescription());
			urlBox.setText(currentPublication.getURL());
		*/	
		}

	}

	public class outputButtonListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent arg0) {
			//currentPDFOutput.outputToPdf(currentPublication, "C:\\");
		}

	}

	public class saveButtonListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent arg0) {

			// Create Publication based upon JTextfields
	/*		Publication dbSaveData = new Publication();

			dbSaveData
					.setPublicationID(Integer.valueOf(publisherBox.getText()));
			dbSaveData.setDescription(descriptionArea.getText());
		
			//Do we allow multiple selections or just one?
			dbSaveData.setContributionType(contribTypeList.getSelectedValue().toString());
			dbSaveData.setPageNumbers(pageNumBox.getText());
			dbSaveData.setPublicationTitle(pubTitleBox.getText());

			if (qaYes.isSelected()) {
				dbSaveData.setQualityAssured(true);
			}
			if (qaNo.isSelected()) {
				dbSaveData.setQualityAssured(false);
			}

			if (confYes.isSelected()) {
				dbSaveData.setConfidential(true);
			}
			if (confNo.isSelected()) {
				dbSaveData.setConfidential(false);
			}
			//Should probably make this a String, else memorize which is true
			if (research.isSelected()) {
				dbSaveData.setResearchOrProfCom(true);
			}
			if (pro_Comm.isSelected()) {
				dbSaveData.setResearchOrProfCom(false);
			}
			
			dbSaveData.setVolumeNumber(Integer.valueOf(volNumBox.getText()));
			dbSaveData.setArticleTitle(articleTitleBox.getText());
			dbSaveData.setDate(yearBox.getText());
			dbSaveData.setURL(urlBox.getText());
			dbSaveData.setISSN(issnBox.getText());
			dbSaveData.setDOI(enterDOIBox.getText());
	
			// Lacking most of author detail here as it's not accessible on net
			AuthorList authorList = new AuthorList();
			// authorList.setStaffSubmitter(Integer.valueOf(idBox.getText()));
			Author author = null;
			String temp = authorsBox.getText();
			String[] authors = temp.split("; ");
			for (int i = 0; i < authors.length; i++) {

				author = new Author();
				temp = authors[i];
				String[] names = temp.split(" ");
				author.setactor_f_name(names[0]);
				author.setactor_l_name(names[1]);
				
				author.setauthorStaffID(Integer.valueOf(idBox.getText()));
				author.setDepartment(unitBox.getText());
				author.setMailCode(mailCodeBox.getText());
				authorList.add(author);
			}

			dbSaveData.setAuthors(authorList);

			DBimpl dbAccess = new DBimpl("sec");
			try {
				dbAccess.dbCreator();
				dbAccess.write(dbSaveData);
			} catch (Exception e) {
				e.printStackTrace();
			}
		*/}

	}
}